﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Proxificator
{
    public sealed class Proxy
    {
        private string ipPort;
        private string ip;
        private int port;
        private int status;
        private string country;
        private int speed;
        private static string sPattern =
            @"\b(?:(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[0-1]?[0-9][0-9]?)\:(?:6553[0-5]|655[0-2][0-9]|65[0-4][0-9][0-9]|6[0-4][0-9][0-9][0-9]|[0-5]?[0-9]?[0-9]?[0-9]?[0-9])\b";

        public Proxy(string ipPort, int status, string country)
        {
            if (Regex.IsMatch(ipPort, sPattern))
            {
                this.ipPort = ipPort;
                string[] ss = ipPort.Split(new char[] { ':' });
                this.ip = ss[0];
                this.port = Convert.ToInt32(ss[1]);
                this.status = status;
                this.country = country;
            }
            else
            {
                this.ipPort = "0";
                this.status = -2;
                this.country = "0";
            }
        }

        public string vIpPort
        {
            get
            {
                return this.ipPort;
            }

            set
            {
                this.ipPort = value;
            }
        }

        public int vStatus
        {
            get
            {
                return this.status;
            }
            set
            {
                this.status = value;
            }
        }

        public string vIp
        {
            get
            {
                return this.ip;
            }
            set
            {
                this.ip = value;
            }
        }

        public int vPort
        {
            get
            {
                return this.port;
            }
            set
            {
                this.port = value;
            }
        }

        public int vSpeed
        {
            get
            {
                return this.speed;
            }
            set
            {
                this.speed = value;
            }
        }

        public string vCountry
        {
            get
            {
                return this.country;
            }
            set
            {
                this.country = value;
            }
        }

        public override bool Equals(object obj)
        {
            // Adjust according to requirements
            var other = obj as Proxy;
            if (other == null)
            {
                return false;
            }
            return (this.vIpPort == other.vIpPort);
        }

        public override int GetHashCode()
        {
            return this.vIpPort.GetHashCode();
        }

        public override string ToString()
        {
            return this.ipPort;
        }
    }
}
